package c926.xiaoduyun.xiaodu.mservice;

import kd.bos.dataentity.entity.DynamicObject;
import kd.bos.dataentity.entity.DynamicObjectCollection;
import kd.bos.entity.ExtendedDataEntity;
import kd.bos.entity.botp.plugin.AbstractConvertPlugIn;
import kd.bos.entity.botp.plugin.args.AfterConvertEventArgs;
import kd.bos.logging.Log;
import kd.bos.logging.LogFactory;
import kd.bos.orm.query.QCP;
import kd.bos.orm.query.QFilter;
import kd.bos.servicehelper.BusinessDataServiceHelper;
import kd.sdk.plugin.Plugin;

/**
 * 单据转换插件
 */
public class XiaoduStartAfterConvertPlugin extends AbstractConvertPlugIn implements Plugin {

    private final static Log logger = LogFactory.getLog(XiaoduStartAfterConvertPlugin.class);

    @Override
    public void afterConvert(AfterConvertEventArgs e) {
        super.afterConvert(e);
        System.out.println();
        ExtendedDataEntity[] xiaoduRecords = e.getTargetExtDataEntitySet().FindByEntityKey("c926_xiaodurecord");
        for (ExtendedDataEntity xiaoduRecord : xiaoduRecords) {
            String recordNo = xiaoduRecord.getDataEntity().getString("c926_xiaoduid");
            QFilter filter = new QFilter("billno", QCP.equals, recordNo);
            DynamicObject xiaoduRecord4Db = BusinessDataServiceHelper.loadSingle("c926_xiaodurecord", filter.toArray());
            long schemeId = xiaoduRecord4Db.getLong("c926_scheme.id");
            logger.info("schemeId" + schemeId);
            DynamicObject scheme4Db = BusinessDataServiceHelper.loadSingle(schemeId, "c926_scheme");
            DynamicObjectCollection levels = scheme4Db.getDynamicObjectCollection("c926_levelentity");
            System.out.println();
        }

    }
}